<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>展开运算符的复习</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
</head>

<body>
  
    <script>
   //...展开运算符，展开数组
    let a =[1,2,3,4]
    let b =[4,5,6,7]
    const d =[...a]
    console.log(d)
    const c =[...a,...b] 
    console.log(c)

    //展开传的参数
    function sum(...c){

        //reduce方法可以执行求数组中所有值之和的操作（红宝书98页）
        const number= c.reduce(function(prev,cur){
        return prev+cur 
    })

    console.log(number)
    }
    sum(1,2,3,4,5,6)

    //展开运算符不能展开对象
    //构造字面量独对象使用展开语法

    let person ={name:"邓紫棋",age :18}
    let person2 =person
    
    person.name="周杰伦"
    console.log(person2) //浅拷贝


    var obj1 ={name:"邓紫棋22",age :183}
    var obj2 ={name:"邓紫棋33",age :138}

    var colObj ={...obj1}   //克隆后的对象 ，{name:"邓紫棋22",age :183}
    console.log(colObj)
    colObj.name ="刘德华"
    console.log(obj1)
    var hbObj ={...obj1,...obj2}  //合并后的对象{name:"邓紫棋22",name:"邓紫棋33", age :183,age :138}
     
   



    </script>

   



</body>

</html>